%{
#include "parser.tab.h"
#include <string.h>
%}

%option noyywrap

DIGIT    [0-9]
ID       [a-zA-Z_][a-zA-Z0-9_]*

%%

{DIGIT}+       { yylval.num = atoi(yytext); return NUMBER; }
{DIGIT}+"."{DIGIT}*  { yylval.fnum = atof(yytext); return FLOAT; }
"if"          { return IF; }
"else"        { return ELSE; }
"def"         { return DEF; }
"return"      { return RETURN; }
"print"       { return PRINT; }
{ID}          { yylval.str = strdup(yytext); return IDENTIFIER; }
"="           { return ASSIGN; }
"=="          { return EQ; }
"+"           { return PLUS; }
"-"           { return MINUS; }
"*"           { return TIMES; }
"/"           { return DIVIDE; }
":"           { return COLON; }
"("           { return LPAREN; }
")"           { return RPAREN; }
"["           { return LBRACKET; }
"]"           { return RBRACKET; }
","           { return COMMA; }
\n            { return NEWLINE; }
[ \t]         ; /* 忽略空白 */
"#".*         ; /* 忽略注释 */
.             { printf("未知字符: %s\n", yytext); }

%%